import unittest


class Solution:
    def longestSemiRepetitiveSubstring(self, s: str) -> int:
        if len(s) == 1:
            return 1
        ret = 0
        right = 0
        repeat_count = 0
        for left in range(0, len(s) - 1):
            while right + 1 < len(s):
                if s[right] != s[right + 1]:
                    right += 1
                    continue
                else:
                    if repeat_count == 0:
                        repeat_count += 1
                        right += 1
                        continue
                    else:
                        break
            ret = max(ret, right - left + 1)
            if s[left] == s[left + 1]:
                repeat_count -= 1
        return ret

class Test(unittest.TestCase):
    def test_case1(self):
        s = Solution()
        act = s.longestSemiRepetitiveSubstring("52233")
        self.assertEqual(act, 4)

    def test_case2(self):
        s = Solution()
        act = s.longestSemiRepetitiveSubstring("5494")
        self.assertEqual(act, 4)

    def test_case3(self):
        s = Solution()
        act = s.longestSemiRepetitiveSubstring("001")
        self.assertEqual(act, 3)

    def test_case4(self):
        s = Solution()
        act = s.longestSemiRepetitiveSubstring("00")
        self.assertEqual(act, 2)

    def test_case5(self):
        s = Solution()
        act = s.longestSemiRepetitiveSubstring("0")
        self.assertEqual(act, 1)
